﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.StopZero.CUiStopZeroDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Markup;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;
using UiInternalControls;


namespace DnProcessSimulateCommands.StopZero;

public class CUiStopZeroDlg : TxWindow, IComponentConnector
{
  private CApStopZeroApp _app;
  private const int DIALOG_MIN_WIDTH = 250;
  internal TxObjEditBoxControl StartLocationPicker;
  internal TxObjEditBoxControl EndLocationPicker;
  internal TxObjEditBoxControl SpheresPicker;
  internal TxObjEditBoxControl ResultContainerPicker;
  internal ComboBox StopTypeComboBox;
  internal TxNumericEditBoxControl m_timeInterval;
  internal TextBlock m_unitLabel;
  internal Button CreateButton;
  internal Button StopButton;
  private bool _contentLoaded;

  public CUiStopZeroDlg()
  {
    this._app = new TxRegistrySerializer<CApStopZeroApp>((TxWindow) this).Deserialize();
    this.InitializeComponent();
    this.InitPickers();
    ((FrameworkElement) this).DataContext = (object) this._app;
    this.StartLocationPicker.Focus();
  }

  private static void EnterBusyMode()
  {
    Mouse.OverrideCursor = Cursors.Wait;
    Mouse.UpdateCursor();
    TxApplicationEx.FreezeDisplay();
  }

  private static void ExitBusyMode()
  {
    TxApplicationEx.UnfreezeDisplay();
    TxApplication.RefreshDisplay();
    Mouse.OverrideCursor = (Cursor) null;
    Mouse.UpdateCursor();
  }

  private void InitPickers()
  {
    // ISSUE: unable to decompile the method.
  }

  private void InitResultContainerPicker(TxPickProvider[] pickProviders)
  {
    this.ResultContainerPicker.SetPickProviders(pickProviders);
    this.ResultContainerPicker.SetValidator((ITxValidator) this._app.ResultContainerValidator);
    this.ResultContainerPicker.ListenToPick = true;
  }

  private void InitEndLocationPicker(TxPickProvider[] pickProviders)
  {
    this.EndLocationPicker.SetPickProviders(pickProviders);
    this.EndLocationPicker.SetValidator((ITxValidator) this._app.EndLocationValidator);
    this.EndLocationPicker.ListenToPick = true;
  }

  private void InitStartLocationPicker(TxPickProvider[] pickProviders)
  {
    this.StartLocationPicker.SetPickProviders(pickProviders);
    this.StartLocationPicker.SetValidator((ITxValidator) this._app.StartLocationValidator);
    this.StartLocationPicker.ListenToPick = true;
  }

  private void InitSpheresPicker(TxPickProvider[] pickProviders)
  {
    this.SpheresPicker.SetPickProviders(pickProviders);
    this.SpheresPicker.SetValidator((ITxValidator) this._app.SpheresValidator);
    this.SpheresPicker.ListenToPick = true;
  }

  private void SpheresContainerPicked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    if (!args.IsValidObjectPicked)
      return;
    this.ResultContainerPicker.Focus();
  }

  private void StartLocationPickerPicked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    if (!args.IsValidObjectPicked)
      return;
    if (args.Object is ITxRoboticOrderedCompoundOperation)
      this.SpheresPicker.Focus();
    else
      this.EndLocationPicker.Focus();
  }

  private void EndLocationPickerPicked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    if (!args.IsValidObjectPicked)
      return;
    this.SpheresPicker.Focus();
  }

  private void ResultContainerPickerPicked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    if (!args.IsValidObjectPicked)
      return;
    this.CreateButton.Focus();
  }

  private void CreateClick(object sender, RoutedEventArgs e)
  {
    CUiStopZeroDlg.EnterBusyMode();
    this._app.Create();
    CUiStopZeroDlg.ExitBusyMode();
    this.StartLocationPicker.Focus();
  }

  private void StopClick(object sender, RoutedEventArgs e) => this._app.Stop();

  private void CloseClick(object sender, RoutedEventArgs e) => ((Window) this).Close();

  private void WindowClosed(object sender, EventArgs e)
  {
    new TxRegistrySerializer<CApStopZeroApp>((TxWindow) this).Serialize(this._app);
    this._app.Clear();
  }

  private void TxWindow_Loaded(object sender, RoutedEventArgs e)
  {
    this.m_unitLabel.Text = $"({TxApplication.Options.Units.TimeUnitName})";
    this.SetMinWidth();
  }

  private void SetMinWidth()
  {
    double actualWidth = ((FrameworkElement) this).ActualWidth;
    SizeToContent sizeToContent = ((Window) this).SizeToContent;
    // ISSUE: explicit non-virtual call
    __nonvirtual (((FrameworkElement) this).Width) = 250.0;
    ((Window) this).SizeToContent = SizeToContent.WidthAndHeight;
    ((FrameworkElement) this).MinWidth = ((FrameworkElement) this).ActualWidth;
    ((Window) this).SizeToContent = sizeToContent;
    // ISSUE: explicit non-virtual call
    __nonvirtual (((FrameworkElement) this).Width) = ((FrameworkElement) this).MinWidth < actualWidth ? actualWidth : ((FrameworkElement) this).MinWidth;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/stopzero/cuistopzerodlg.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((Window) target).Closed += new EventHandler(this.WindowClosed);
        ((FrameworkElement) target).Loaded += new RoutedEventHandler(this.TxWindow_Loaded);
        break;
      case 2:
        this.StartLocationPicker = (TxObjEditBoxControl) target;
        this.StartLocationPicker.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.StartLocationPickerPicked);
        break;
      case 3:
        this.EndLocationPicker = (TxObjEditBoxControl) target;
        this.EndLocationPicker.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.EndLocationPickerPicked);
        break;
      case 4:
        this.SpheresPicker = (TxObjEditBoxControl) target;
        this.SpheresPicker.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.SpheresContainerPicked);
        break;
      case 5:
        this.ResultContainerPicker = (TxObjEditBoxControl) target;
        this.ResultContainerPicker.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.ResultContainerPickerPicked);
        break;
      case 6:
        this.StopTypeComboBox = (ComboBox) target;
        break;
      case 7:
        this.m_timeInterval = (TxNumericEditBoxControl) target;
        break;
      case 8:
        this.m_unitLabel = (TextBlock) target;
        break;
      case 9:
        this.CreateButton = (Button) target;
        this.CreateButton.Click += new RoutedEventHandler(this.CreateClick);
        break;
      case 10:
        this.StopButton = (Button) target;
        this.StopButton.Click += new RoutedEventHandler(this.StopClick);
        break;
      case 11:
        ((ButtonBase) target).Click += new RoutedEventHandler(this.CloseClick);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
